package org.moonshiner.controller.web;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import org.moonshiner.controller.service.UserService;
import org.moonshiner.model.enums.UserRole;
import org.moonshiner.model.user.User;

/**
 * Handles requests for the application home page.
 */
@Controller
@RequestMapping(value = "/")
public class HomeController {

	@Autowired
	private UserService userService;

	/**
	 * Simply selects the home view to render by returning its name.
	 */
	@RequestMapping(value = "/welcome", method = RequestMethod.GET)
	public String home(Model model) {

		model.addAttribute("time", new Date());

		return "home";
	}

	@RequestMapping(value = "/login", method = RequestMethod.GET)
	public String login() {
		return "login";
	}

	@RequestMapping(value = "/test", method = RequestMethod.GET)
	public String test() {

		User user = new User();
		user.setName("name");
		user.setPassword("password");
		user.setRole(UserRole.USER);

		userService.save(user);
		return "home";
	}

}
